/*
 * CMP.c
 *
 *  Created on: Jan 18, 2014
 *      Author: adijoshi
 */
//INCLUDES
#include "includes.h"
/*
 * Function: func_CMP
 *
 * Inputs:	 Mnemonic, Address_of_source, Address_of_destination
 * Outputs:  (None)
 * Condition  Codes:
 * 		Z:  set  if  result  =  0;  cleared  otherwise
 * 		N:  set  if  result  <  0;  cleared  otherwise
 * 		C:  cleared  if  there  was  a  carry  from  the  most  significant bit  of  the  result;  set  otherwise
 * 		V:  set  if  there  was  arithmetic  overflow;  that  is,  operands were  of  opposite  signs  and  the
 * 			sign  of  the  destination was  the  same  as  the  sign  of  the  result;  cleared otherwise.
 *
 */

void func_CMP(unsigned short address_source, unsigned short address_destination)
{
	unsigned short data_source;
	unsigned short data_destination;
	unsigned short result;
	int result_32_bit;

	data_source		 = read_from_memory(address_source, DATA);
	data_destination = read_from_memory(address_destination, DATA);

	result_32_bit	 = data_source + get_twos_complement(data_destination);
	result			 = (unsigned short) result_32_bit;

	update_Z_flag(result);
	update_N_flag(CMP,result);
	update_V_flag(CMP,data_source,data_destination,result);
	update_C_flag(CMP,data_source,data_destination,result,result_32_bit);
}



